//
//  GYOrderDetailCollectionViewCell.m
//  GoodLuck
//
//  Created by 郭为勇 on 2018/3/22.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYOrderDetailCollectionViewCell.h"

@interface GYOrderDetailCollectionViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *goodsImageView;
@property (weak, nonatomic) IBOutlet UILabel *goodsNameLable;
@property (weak, nonatomic) IBOutlet UILabel *goodsPriceLable;
@property (weak, nonatomic) IBOutlet UILabel *goodsNumLable;
@property (weak, nonatomic) IBOutlet UIButton *cancelBtu;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *cancelBtuHeightCons;

@end
@implementation GYOrderDetailCollectionViewCell

- (IBAction)cacelBtuClick:(UIButton *)sender {
    if (self.isIf_lock) {
        UIAlertView *alertView =[[UIAlertView alloc] initWithTitle:@"该商品退款正在审核中,不能重复操作!" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
    }else {
        //点击退款按钮吧 商品模型传递出去
        [[NSNotificationCenter defaultCenter]postNotificationName:@"orderDetailsInfoGoods" object:self.orderGoods];
    }
}

- (void)setIf_lock:(BOOL)if_lock {
    _if_lock = if_lock;
    
    if (if_lock) {
        //代表退款中
        [self.cancelBtu setTitle:@"退款中" forState:UIControlStateNormal];
    }else {
        //代表还没有退款
        [self.cancelBtu setTitle:@"商品退款" forState:UIControlStateNormal];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.cancelBtu.layer.cornerRadius = 4;
    self.cancelBtu.layer.borderColor = RGBColor(221, 221, 221).CGColor;
    self.cancelBtu.layer.borderWidth = 1;
}

- (void)setOrderGoods:(GYOrderGoods *)orderGoods {
    _orderGoods = orderGoods;
    
    //NSLog(@"goodsuRL======%@",orderGoods.image_60_url);
    [self.goodsImageView sd_setImageWithURL:[NSURL URLWithString:orderGoods.image_60_url] placeholderImage:[UIImage imageNamed:@"4"]];
    self.goodsNameLable.text = orderGoods.goods_name;
    self.goodsPriceLable.text = [NSString stringWithFormat:@"¥%@",orderGoods.goods_price];
    self.goodsNameLable.text = [NSString stringWithFormat:@"x%@",orderGoods.goods_num];
    
}

- (void)setOrder_state:(NSString *)order_state {
    _order_state = order_state;
    
    switch ([order_state integerValue]) {
        case 0:
        {
            self.cancelBtuHeightCons.constant = 0;
            self.cancelBtu.hidden = YES;
        }
            break;
            
        case 10:
        {
            self.cancelBtuHeightCons.constant = 0;
            self.cancelBtu.hidden = YES;
        }
            break;
            
        case 20:
        {
            self.cancelBtuHeightCons.constant = 35;
            self.cancelBtu.hidden = NO;
        }
            break;
            
        case 30:
        {
            self.cancelBtuHeightCons.constant = 35;
            self.cancelBtu.hidden = NO;
        }
            break;
            
        case 40:
        {
            self.cancelBtuHeightCons.constant = 0;
            self.cancelBtu.hidden = YES;
        }
            break;
            
        default:
            break;
    }

}

- (CGFloat)getHeight:(GYOrderGoods *)model {
    self.orderGoods = model;
    
    [self layoutIfNeeded];
    
    return CGRectGetMaxY(self.cancelBtu.frame)+10;
}
@end
